package com.coc.ofhibernate.dao;

import com.coc.ofhibernate.entity.database1.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface UserMapper extends JpaRepository<User,Integer> {

    @Query("SELECT U FROM User U WHERE ID = ?1 ")
    public User getUserById(int id);

    /**
     * nativeQuery = true 使用sql，不适用hql
     * @param id
     * @return
     */
    @Query(value = "SELECT * FROM USER U WHERE U.ID = ? ",nativeQuery = true)
    public User getUserById2(int id);


    @Query(value = "select u from User u where username = ?1")
    public List<User> getUserListByName2(String username);

    @Query(value = "from User u where username = ?1")
    public List<User> getUserListByName1(String username);

    @Query(value = "select user from User as user where username = :username")
    public List<User> getUserListByName(@Param("username") String username);

//    @Modifying
//    @Query("update User u set u.address=:address where u.username = :username")
//    int updateUserStatus(@Param("address") String newAddress,@Param("username") String name);




}
